package com.ruoyi.system.translate.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.common.translate.constant.Translate;
import com.ruoyi.common.translate.NameProvider;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 用户名称映射
 */
@Service
public class UserNameProvider extends NameProvider<SysUser> {

    @Resource
    private SysUserMapper sysUserMapper;


    @Override
    public String getType() {
        return Translate.Type.USER;
    }

    @Override
    public SysUser findEntity(String id) {
        Long userId = changeIdType(id);
        return sysUserMapper.selectUserById(userId);
    }

    @Override
    public List<SysUser> findEntityList(List<String> keys) {
        ArrayList<SysUser> ret = new ArrayList<>();
        //TODO 批量查询
        for (String key : keys) {
            Long id = changeIdType(key);
            ret.add(sysUserMapper.selectUserById(id));
        }
        return ret;
    }

    @Override
    public Map<String, String> mapName(SysUser obj) {
        HashMap<String, String> ret = new HashMap<>();
        ret.put(baseKey + obj.getUserId(), obj.getUserName());
        return ret;
    }
}